import pandas as pd
import json


def process1(file_path):
    df = pd.read_excel(file_path)
    # 确保列名正确
    df.columns = ['question', 'answer']

    # for 循环每一行，把 question 和 answer 去掉空格和换行符
    json_data = []
    for index, row in df.iterrows():
        idx = index
        q = row['question'].strip()
        a = row['answer'].strip()
        json_data.append({'idx': idx, 'question': q, 'answer': a})

    return json_data


if __name__ == '__main__':
    # 读取 Excel 文件
    file_path = 'data/ai_data.xlsx'  # Excel 文件路径

    # 处理数据
    json_data = process1(file_path)

    # 写入 JSON 文件
    with open('data/do1_QA.json', 'w', encoding='utf-8') as json_file:
        json.dump(json_data, json_file, ensure_ascii=False, indent=4)
